# -*- coding: utf-8 -*-
"""
Created on Mon Feb 18 15:17:28 2013

@author: Daniel
"""
from PBDO import triangle, parameters, PBDO
#--------------Test Problem 1---------------    
def test1_ob(d,x,P):
    f=x[0]+x[1]
    return f
def test1_C1(d,x,P):
    C1=x[0]**2*x[1]/20.0-1.
    return C1
def test1_C2(d,x,P):
    C2=(x[0]+x[1]-5.0)**2/30.+(x[0]-x[1]-12.0)**2/120.0-1.
    return C2
def test1_C3(d,x,P):
    C3=80.0/(x[0]**2+8.0*x[1]+5.0)-1
    return C3
#--------------Test Problem 2---------------  
def test2_ob(d,x,P):
    f=d[0]*d[1]
    return f
def test2_C1(d,x,P):
    C1=P[2]-(600./d[0]/d[1]**2*P[0]+600./d[0]**2/d[1]*P[1])
    return C1
def test2_C2(d,x,P):
    D0=2.5
    L=100.0
    C2=D0-4.0*L**3/(P[3]*10.**7)/d[0]/d[1]*((P[0]/d[1]**2)**2+(P[1]/d[0]**2)**2)**.5
    return C2

tri=triangle()
params=parameters()
params.addFuzzyVar(tri.getFuzzyNumber(3.6,5.0,6.4),0,10)
tri=triangle()
params.addFuzzyVar(tri.getFuzzyNumber(4.3,5.0,5.7),0,10)
opt=PBDO(test1_ob,(test1_C1,test1_C2,test1_C3),params,dx=10**-10,alpha=0.02,nCPU=1)  
opt.solve()
opt.display()
print opt.x0
print opt.d0
print opt.fHistory
print opt.xHistory
print opt.fMin
print opt.xMin
print opt.dMin

params=parameters()
tri=triangle()
params.addFuzzyParam(tri.getFuzzyNumber(900.,1000.,1100.))
tri=triangle()
params.addFuzzyParam(tri.getFuzzyNumber(400.,500.,600.))
tri=triangle()
params.addFuzzyParam(tri.getFuzzyNumber(38000.,40000.,42000.))
tri=triangle()
params.addFuzzyParam(tri.getFuzzyNumber(2.755,2.900,3.045))
tri=triangle()
params.addDeterminisitcVar([1.,1.],[0.1,0.1],[10.,10.]) 

cons=list()
opt=PBDO(test2_ob,(test2_C1,test2_C2),params,dx=10**-7,alpha=0.05,nCPU=1,optimizer='SLSQP') 
opt.solve()
print opt.x0
print opt.d0
print opt.fHistory
print opt.dHistory
print opt.fMin
print opt.xMin
print opt.dMin
opt.display()
